package easylog

import (
	"fmt"
	"log/slog"
	"sync/atomic"
)

var defaultLogger atomic.Pointer[EasyLogger]

func SetDefault(filePath string, level slog.Level) {
	defaultLogger.Store(NewEasyLogger(level, filePath, nil, 4))
}

func SetLogLevel(level slog.Level) {
	defaultLogger.Load().SetLogLevel(level)
}

func init() {
	SetDefault("", slog.LevelDebug)
}

func defaultLog() *EasyLogger {
	return defaultLogger.Load()
}

func Debug(format string, v ...any) {
	defaultLog().Debug(fmt.Sprintf(format, v...))
}

func Info(format string, v ...any) {
	defaultLog().Info(fmt.Sprintf(format, v...))
}

func Warn(format string, v ...any) {
	defaultLog().Warn(fmt.Sprintf(format, v...))
}

func Error(format string, v ...any) {
	defaultLog().Error(fmt.Sprintf(format, v...))
}

func Println(format string, v ...any) {
	defaultLog().Println(format, v...)
}
